package com.zhang.internalcommon.dto;

import com.zhang.internalcommon.constant.CommonStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class ResponseResult<T> {
	private int code;
	private String message;
	private T data;

	/**
	 * 成功响应的方法
	 * @param <T>
	 * @return
	 */
	public static <T> ResponseResult success(){
		return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue());
	}

	/**
	 * 成功返回值
	 * @param data 数据
	 * @return
	 * @param <T>
	 */
	public static <T> ResponseResult<T> success(T data) {
		return new ResponseResult<T>().setCode(CommonStatusEnum.SUCCESS.getCode())
				.setMessage(CommonStatusEnum.SUCCESS.getValue()).setData(data);
	}

	/**
	 * 失败响应值
	 * @param data
	 * @return
	 * @param <T>
	 */
	public static <T> ResponseResult<T> fail(T data) {
		return new ResponseResult<T>().setCode(CommonStatusEnum.FAIL.getCode())
				.setMessage(CommonStatusEnum.FAIL.getValue()).setData(data);
	}

	/**
	 * 失败响应值不带数据
	 * @param code 状态码
	 * @param msg 信息
	 * @return
	 * @param <T>
	 */
	public static <T> ResponseResult<T> fail(int code,String msg) {
		return new ResponseResult<T>().setCode(code).setMessage(msg);
	}

	/**
	 * 失败响应值
	 * @param code 状态码
	 * @param msg 信息
	 * @param data 数据
	 * @return
	 * @param <T>
	 */
	public static <T> ResponseResult<T> fail(int code,String msg, T data) {
		return new ResponseResult<T>().setCode(code).setMessage(msg).setData(data);
	}
}
